mui.init();

//获取本地信息
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		self = plus.webview.currentWebview();
		//查询指定商家信息  在线商家入驻
		document.getElementById("online_merchant").addEventListener("tap", function() {
			var businessType = $(this).attr('businessType');
			mui.ajax(user_url + '/business/getZbusinessInfo', { //
				data: {
					"userId": user_id,
					"businessType": businessType
				},
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					if(data.code == 10000) {
						if(data.resp == null) {
							mui.openWindow({
								url: "online_merchants_enter.html",
								id: "online_merchants_enter",
								extras: {
									businessType: businessType
								}
							});
						} else {
							var examineState = data.resp.examineState; //审核 状态
							if(examineState == 0) {
								mui.alert('正在审核请等待');
								return;
							}
							if(examineState == 1) {
								mui.alert('您已是在线商家，请移步商家后台');
								return;
							}
							if(examineState == 2) {
								mui.alert(data.resp.platformRemark, function() {
									mui.openWindow({
										url: "online_merchants_enter.html",
										id: "online_merchants_enter",
										extras: {
											businessType: businessType
										}
									});
								})
								return;
							}
						}

					}
				},
				error: function(xhr, type, errorThrown) { //异常处理；
					console.log(type);
				}
			});
		});

		document.getElementById("alliance_merchant").addEventListener("tap", function() {
			var businessType = $(this).attr('businessType');
			mui.ajax(user_url + '/business/getZbusinessInfo', { //
				data: {
					"userId": user_id,
					"businessType": businessType
				},
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					if(data.code == 10000) {

						if(data.resp == null) {
							mui.openWindow({
								url: "affiliate_merchants_enter.html",
								id: "affiliate_merchants_enter",
								extras: {
									businessType: businessType
								}
							});
						} else {
							var examineState = data.resp.examineState; //审核 状态
							if(examineState == 0) {
								mui.alert('正在审核请等待');
								return;
							}
							if(examineState == 1) {
								mui.alert('您已是联盟商家，请移步商家后台');
								return;
							}
							if(examineState == 2) {
								mui.alert(data.resp.platformRemark, function() {
									mui.openWindow({
										url: "affiliate_merchants_enter.html",
										id: "affiliate_merchants_enter",
										extras: {
											businessType: businessType
										}
									});
								})
								return;
							}
						}

					}
				},
				error: function(xhr, type, errorThrown) { //异常处理；
					console.log(type);
				}
			});
		});
	});
}